/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.com.remiseria.dao;

import ar.com.remiseria.entities.Auto;
import ar.com.remiseria.entities.Chofer;
import ar.com.remiseria.utils.HibernateUtils;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author mcvalls
 */
public class AutoDAO extends GenericDAO{

    public List<Auto> getAutosByChofer(Chofer chofer) throws HibernateException{
        Session session = HibernateUtils.getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();
        
        Criteria criteria = session.createCriteria(Auto.class);
        criteria.add(Restrictions.eq("chofer", chofer));
        
        List<Auto> losAutos = (List<Auto>)criteria.list();
        tx.commit();
        
        return losAutos;
        
    }
    
    
}
